<template>
  <div class="approval">
    <el-card>
      <div class="title">{{$t('callRecord.RecentData')}}</div>
      <div class="recent-data">
        <!-- 今日已接通数量 -->
        <div class="recent-item" @click="recentFn(5)">
          <div>
            <b>{{recentDataObj.connectedCount}}</b>
          </div>
          <div>{{$t('electricRecord.todayConnectNum')}}</div>
        </div>
        <!-- 今日完成数量 -->
        <div class="recent-item" @click="recentFn(6)">
          <div>
            <b>{{recentDataObj.finishCount}}</b>
          </div>
          <div>{{$t('electricRecord.todayCompleteNum')}}</div>
        </div>
        <!-- 历史已接通数量 -->
        <div class="recent-item" @click="recentFn(7)">
          <div>
            <b>{{recentDataObj.connectedHistoryCount}}</b>
          </div>
          <div>{{$t('electricRecord.hisConnectNum')}}</div>
        </div>
        <!-- 历史完成数量 -->
        <div class="recent-item" @click="recentFn(8)">
          <div>
            <b>{{recentDataObj.finishHistoryCount}}</b>
          </div>
          <div>{{$t('electricRecord.hisCompleteNum')}}</div>
        </div>
      </div>
    </el-card>
    <el-card style="margin-top: 10px;">
      <div class="title">{{$t('achievements.title1')}}</div>
      <div class="menu-search">
        <div class="menu-title">
          <!-- 分配时间 -->
          <div class="searchItem searchItem-date">
            <span>{{$t('callRecord.AllocationTime')}}</span>
            <el-date-picker
              size="small"
              v-model="listQuery.distributionStartDate"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('rule.beginDate')"
            ></el-date-picker>
            <b>{{$t('approval.go')}}</b>
            <el-date-picker
              size="small"
              v-model="listQuery.distributionEndDate"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('rule.endDate')"
            ></el-date-picker>
          </div>
          <!-- 电销状态 -->
          <div class="searchItem">
            <span>{{$t('electricRecord.ElectricState')}}</span>
            <el-select v-model="listQuery.telStatus" size="small">
              <el-option
                v-for="item in status"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </div>
          <div class="menu-title-btn">
            <button type="button" @click="search">{{$t('btn.query')}}</button>
            <button type="button" @click="reset">{{$t('btn.reset')}}</button>
          </div>
        </div>
      </div>
    </el-card>
    <el-card style="margin-top: 10px;margin-bottom: 20px;">
      <div class="title">{{$t('approval.title2')}}</div>
      <el-table
        v-loading="listLoading"
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        border
        stripe
        size="mini"
      >
        <el-table-column header-align="center" align="center" width="65" :label="$t('user.num')">
          <template slot-scope="scope">
            <span>{{scope.row.index}}</span>
          </template>
        </el-table-column>
        <!-- 客户姓名 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="userRealName"
          :label="$t('approval.realName')"
          width="140"
        ></el-table-column>
        <!-- 手机号 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="userPhone"
          :label="$t('approval.phoneNo')"
          width="140"
        ></el-table-column>
        <!-- 上一笔结清业务ID -->
        <el-table-column
          header-align="center"
          align="center"
          prop="lastFiveOrderId"
          :label="$t('electricRecord.LastSettleOrderId')"
          width="140"
        ></el-table-column>
        <!-- 结清本金 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="lentAmt"
          :label="$t('electricRecord.settlePrincipal')"
          width="140"
        ></el-table-column>
        <!-- 借款期限 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="pTerm"
          :label="$t('product.LoanPeriod')"
          width="140"
        ></el-table-column>
        <!-- 业务渠道 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="channelName"
          :label="$t('approval.channel')"
          width="140"
        ></el-table-column>
        <!-- 借款App -->
        <el-table-column
          header-align="center"
          align="center"
          prop="appPackageName"
          :label="$t('approvalDetail.loanApp')"
          width="140"
        ></el-table-column>
        <!-- 用户状态 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="saleStatus"
          :label="$t('electricRecord.UserStatus')"
          width="140"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.saleStatus === 1">{{$t('electricRecord.RegistNonBillLading')}}</span>
            <span v-else-if="scope.row.saleStatus === 2">{{$t('electricRecord.AuthNonBillLading')}}</span>
            <span v-else-if="scope.row.saleStatus === 3">{{$t('electricRecord.SettleUnrenewedLoan')}}</span>
            <span v-else-if="scope.row.saleStatus === 4">{{$t('electricRecord.unregistered')}}</span>
          </template>
        </el-table-column>
        <!-- 分配时间 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="distributionTime"
          :label="$t('callRecord.AllocationTime')"
          width="140"
        ></el-table-column>
        <!-- 电销状态 -->
        <el-table-column
          header-align="center"
          align="center"
          prop="telStatus"
          :label="$t('electricRecord.ElectricState')"
          width="140"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.telStatus === 1">{{$t('electricRecord.systemClose')}}</span>
            <span v-else-if="scope.row.telStatus === 2">{{$t('electricRecord.ongoing')}}</span>
            <span v-else-if="scope.row.telStatus === 3">{{$t('callRecord.RetireCase')}}</span>
            <span v-else-if="scope.row.telStatus === 4">{{$t('btn.complete')}}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.page"
          :page-sizes="[5, 10, 20, 30]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { formatAmt } from "utils/index";
import {
  recentData,
  dialPage
} from "api/electricRecord/index";
export default {
  data() {
    return {
      recentDataObj: {
        connectedCount: 0,
        finishCount: 0,
        connectedHistoryCount: 0,
        finishHistoryCount: 0
      },
      listLoading: false,
      total: null,
      listQuery: {
        limit: 5,
        page: 1,
        distributionStartDate: "",
        distributionEndDate: "",
        telStatus: null,
        pageType: 2
      },
      tableData: [],
      status: [
        {
          value: null,
          label: this.$t("rule.all")
        },
        {
          value: 1,
          label: this.$t('electricRecord.systemClose')
        },
        {
          value: 2,
          label: this.$t('electricRecord.ongoing')
        },
        {
          value: 3,
          label: this.$t('callRecord.RetireCase')
        },
        {
          value: 4,
          label: this.$t('btn.complete')
        }
      ]
    };
  },
  created() {
    if (this.ElecDialRecordPage.has(this.$route.path)) {
      this.listQuery = this.ElecDialRecordPage.get(this.$route.path);
    }
    this.getList();
    // 近期数据回显
    let obj = {};
    obj.type = 2;
    recentData(obj).then(res => {
      if (res.status === 200) {
        this.recentDataObj = res.data;
      } else {
        this.$message({
          showClose: true,
          type: "warning",
          message: res.message
        });
      }
    });
  },
  computed: {
    ...mapGetters(["elements", "ElecDialRecordPage"])
  },
  methods: {
    // 点击近期数据
    recentFn(type) {
      this.listQuery.page = 1;
      this.listQuery.pageType = type;
      this.getList();
    },
    getList() {
      this.listLoading = true;
      this.$store.dispatch("saveElecDialRecordPage", {
        path: this.$route.path,
        listQuery: this.listQuery
      });
      dialPage(this.listQuery).then(res => {
        if (res.status === 200) {
          res.data.rows.forEach(item => {
            if (item.lentAmt) {
              item.lentAmt = formatAmt(item.lentAmt);
            }
          });
          this.listLoading = false;
          this.tableData = res.data.rows;
          this.tableData.forEach((item, index) => {
            item.index =
              index + (this.listQuery.page - 1) * this.listQuery.limit + 1;
          });
          this.total = Number(res.data.total);
        } else {
          this.$message({
            showClose: true,
            type: "warning",
            message: res.message
          });
        }
      });
    },
    //查询
    search() {
      this.listQuery.page = 1;
      this.listQuery.pageType = 2;
      this.getList();
    },
    //重置
    reset() {
      this.listQuery.limit = 5;
      this.listQuery.page = 1;
      this.listQuery.distributionStartDate = '';
      this.listQuery.distributionEndDate = '';
      this.listQuery.telStatus = null;
      this.listQuery.pageType = 2;
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    }
  }
};
</script>

<style scoped lang='scss'>
.title {
  line-height: 30px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before {
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-title {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .searchItem {
    display: flex;
    align-items: center;
    padding: 10px 0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div:nth-child(2) {
      width: 150px;
    }
  }
  .searchItem-date {
    display: flex;
    align-items: center;
    padding: 10px 0;
    b {
      margin: 0 10px;
      font-weight: normal;
      font-size: 12px;
      color: #5f5f61;
    }
    div {
      width: 150px;
    }
  }
}
.menu-title-btn {
  padding: 10px 0;
  box-sizing: border-box;
  margin-left: 20px;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
    &:nth-child(2) {
      background: #ebf5ff;
      color: #20a0ff;
      border: 1px solid #abd5ff;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.menu-list {
  padding: 20px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.href {
  border-bottom: 1px solid #000;
  cursor: pointer;
  &:hover {
    color: #20a0ff;
    border-bottom: 1px solid #20a0ff;
  }
}
.recent-data {
  display: flex;
  flex-wrap: wrap;
  font-size: 14px;
  margin-bottom: 10px;
  .recent-item {
    height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px solid #aaa;
    text-align: center;
    border-radius: 10px;
    margin-top: 10px;
    margin-right: 40px;
    padding: 10px 20px;
    box-sizing: border-box;
    cursor: pointer;
    & > div:nth-child(1) {
      line-height: 24px;
      b {
        font-size: 18px;
      }
    }
  }
}
</style>